package com.vrsys.controller;

import java.util.ArrayList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.vrsys.domain.Comments;
import com.vrsys.service.CommentsService;
import com.vrsys.view.PageQuery;

@Controller
@RequestMapping("/comments")
public class CommentsController extends BaseController {
    @Autowired
    private CommentsService commentsService;

    /*
     * This is Ajax calling.
     * @RequestBody cannot be used here since the MediaType is
     */
    @RequestMapping(value = "/{pid}/morecomments.od",method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody PageQuery<Comments> queryMoreProducts(@PathVariable("pid") int pid, PageQuery<Comments> pageQuery) {
        try {
            commentsService.pagingComments(pageQuery,pid);
        } catch (Exception e) {
            logger.error("{}",e);
            pageQuery.setData(new ArrayList<Comments>(0));
        }
        return pageQuery;
    }
/*
    
     * This is Ajax calling.
     * 
     
    @RequestMapping(value = "/{pid}/productdetails.od",method = RequestMethod.GET)
    public ModelAndView showProductDetails(@PathVariable("pid") String pid, ModelAndView mv) {
        try {
            mv.addObject("product", productService.queryDetailsBytId(Integer.valueOf(pid).intValue()));
            mv.setViewName("productdetails");
        } catch (Exception e) {
            logger.error("",e);
        }
        return mv;
    }*/
/*
    @RequestMapping(value = "/moreproducts1.od",method = RequestMethod.POST, consumes=MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody PageQuery<Product> queryMoreProducts1(@RequestBody PageQuery<Product> pageQuery) {
        List<Product> products;
        pageQuery.setLanguage(this.lang);
        try {
            products = productService.getProducts(pageQuery);
        } catch (Exception e) {
            logger.error("",e);
            pageQuery.setData(new ArrayList<Product>(0));
            return pageQuery;
        }
        pageQuery.setFromIndex(pageQuery.getFromIndex() + pageQuery.getToIndex());
        pageQuery.setData(null == products ? new ArrayList<Product>(0) : products);
        return pageQuery;
    }*/
}
